package com.ybt.heartratem.logic.data.local;

import me.goldze.mvvmhabit.utils.SPUtils;

/**
 * 本地数据源，可配合Room框架使用
 */
public class LocalDataSourceImpl implements LocalDataSource {
    private volatile static LocalDataSourceImpl INSTANCE = null;

    public static LocalDataSourceImpl getInstance() {
        if (INSTANCE == null) {
            synchronized (LocalDataSourceImpl.class) {
                if (INSTANCE == null) {
                    INSTANCE = new LocalDataSourceImpl();
                }
            }
        }
        return INSTANCE;
    }

    public static void destroyInstance() {
        INSTANCE = null;
    }

    private LocalDataSourceImpl() {
        //数据库Helper构建
    }

    @Override
    public void saveInitPage(boolean flag) {
        SPUtils.getInstance().put("initPage", flag);
    }

    @Override
    public void saveUserName(String userName) {
        SPUtils.getInstance().put("UserName", userName);
    }

    @Override
    public void savePassword(String password) {
        SPUtils.getInstance().put("password", password);
    }

    @Override
    public void saveToken(String token) {
        SPUtils.getInstance().put("token", token);
    }

    @Override
    public void saveConfigInfo(String config) {
        SPUtils.getInstance().put("config", config);
    }

    @Override
    public void saveLoginUser(String loginUser) {
        SPUtils.getInstance().put("loginUser", loginUser);
    }

    @Override
    public void saveIsQueryLocalDB(String key, boolean value) {
        SPUtils.getInstance().put(key, value);
    }

    @Override
    public boolean getInitPage() {
        return SPUtils.getInstance().getBoolean("initPage");
    }

    @Override
    public String getUserName() {
        return SPUtils.getInstance().getString("UserName");
    }

    @Override
    public String getPassword() {
        return SPUtils.getInstance().getString("password");
    }

    @Override
    public String getToken() {
        return SPUtils.getInstance().getString("token");
    }

    @Override
    public String getConfigInfo() {
        return SPUtils.getInstance().getString("config");
    }

    @Override
    public String getLoginUser() {
        return SPUtils.getInstance().getString("loginUser");
    }

    @Override
    public boolean getQueryLocalDB(String key) {
        //默认是需要查询本地数据库
        return SPUtils.getInstance().getBoolean(key, true);
    }

}
